package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.JobOption;
import com.itheima.service.StatisticService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class StatisticServiceImpl implements StatisticService {

    @Autowired
    private EmpMapper empMapper;
    @Override
    public JobOption jobEmpCount() {
        List<Map<String, Object>> list = empMapper.countJobEmp();
        log.info("统计每个职位的人数: {}", list);

        List<Object> jobList = list.stream().map(map -> map.get("pos")).toList();
        List<Object> dataList = list.stream().map(map -> map.get("num")).toList();

        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> genderCount() {
        List<Map<String, Object>> list = empMapper.countGenderEmp();
        log.info("统计性别人数: {}", list);
        return list;
    }
}
